import { http } from "@/utils/http";
import { baseUrlApi } from "@/api/utils";
import { message } from "@/utils/message";
type Result = {
  current_page: number;
  result?: any;
  per_page?: number;
  total?: number;
  data?: any;
};
type ResultDelete = {
  code: number;
  msg: string;
};
type ResultCreate = {
  code: number;
  msg: string;
};
/** 库位列表 */
export const getLocationListApi = (params?: object) => {
  return http.request<Result>(
    "get",
    baseUrlApi + "/admin/warehouseGoodsLocation/list",
    {
      params
    }
  );
};

/** 添加*/
export const createLocationApi = (data?: object) => {
  return http
    .request<ResultCreate>(
      "post",
      baseUrlApi + "/admin/warehouseGoodsLocation/store",
      {
        data
      }
    )
    .catch(error => {
      message(error.response.data.msg ?? "操作失败,请联系管理员", {
        type: "error"
      });
    });
};
/** 修改 */
export const updateLocationApi = (data?: object) => {
  return http
    .request<ResultCreate>(
      "put",
      baseUrlApi + "/admin/warehouseGoodsLocation/update",
      {
        data
      }
    )
    .catch(error => {
      message(error.response.data.msg ?? "操作失败,请联系管理员", {
        type: "error"
      });
    });
};
export const delLocationApi = (params?: object) => {
  return http
    .request<ResultDelete>(
      "delete",
      baseUrlApi + "/admin/warehouseGoodsLocation/delete",
      {
        params
      }
    )
    .catch(error => {
      message(error.response.data.msg ?? "操作失败,请联系管理员", {
        type: "error"
      });
    });
};
type Show = {
  code: number;
  msg: string;
  result?: any;
};
/** 详情 */
export const getLocationShowApi = (params?: object) => {
  return http.request<Show>(
    "get",
    baseUrlApi + "/admin/warehouseGoodsLocation/show",
    {
      params
    }
  );
};
